﻿Imports ADOEntityKYC
Imports System.Data
Partial Class Form_KYC2T_01
    Inherits System.Web.UI.Page

    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim ds As DataSet

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ds = Session("ds")

        bindingData()

        userPrint()

        'Dim pageKey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\microsoft\internet explorer\pagesetup", True)

        'pageKey.SetValue("footer", "")
        'pageKey.SetValue("header", "")
        ''pageKey.SetValue("margin_left", "")
        ''pageKey.SetValue("margin_top", "")
        'pageKey.Close()

        Response.Write("<script>")
        Response.Write("window.print()")
        Response.Write("</script>")

    End Sub

    Private Sub bindingData()

        Dim CUSTSEQ As Integer = Request.QueryString("CUSTSEQ")
        Dim KYCSEQ As Integer = Request.QueryString("KYCSEQ")
        Dim qryCust As Object
        If KYCSEQ = 0 Then
            qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join occ In KYCEntity.MOCCUPATION On cust.OCCUPATIONTYPE1 Equals occ.OCCCODE
               Into aOcc = Group From leftOcc In aOcc.DefaultIfEmpty
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ
               Select cust, p.PREFIXTH, leftOcc.OCCNAME, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList


        Else
            qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join occ In KYCEntity.MOCCUPATION On cust.OCCUPATIONTYPE1 Equals occ.OCCCODE
               Into aOcc = Group From leftOcc In aOcc.DefaultIfEmpty
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Group Join kyc In (From tblKyc In KYCEntity.RKYC Where tblKyc.ANSWERTYPE = 3 Select tblKyc) On cust.CUSTSEQ Equals kyc.CUSTSEQ
               Into d = Group From leftD In d.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ And leftD.KYCSEQ = KYCSEQ
               Select cust, leftD, p.PREFIXTH, leftOcc.OCCNAME, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList

            If Not qryCust(0).leftD Is Nothing Then
                If qryCust(0).leftD.ANSWER101 = 0 Then
                    lblAns101.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER102 = 0 Then
                    lblAns102.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER103 = 0 Then
                    lblAns103.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER104 = 0 Then
                    lblAns104.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER105 = 0 Then
                    lblAns105.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER106 = 0 Then
                    lblAns106.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER107 = 0 Then
                    lblAns107.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER108 = 0 Then
                    lblAns108.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER109 = 0 Then
                    lblAns109.Text = "x"
                End If
                If qryCust(0).leftD.ANSWER110 = 0 Then
                    lblAns110.Text = "x"
                    lblAns199.Text = qryCust(0).leftD.ANSWER199
                End If

            End If
            lblAccountno.Text = qryCust(0).leftD.ACCOUNTNO

        End If
       
        If Not qryCust.Count = 0 Then

            lblTHName.Text = qryCust(0).cust.THFIRSTNAME + " " + qryCust(0).cust.THMIDNAME
            lblTHLastName.Text = qryCust(0).cust.THLASTNAME

            If qryCust(0).cust.THPREFIX = 1 Then
                lblPrefix1.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 2 Then
                lblPrefix2.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 3 Then
                lblPrefix3.Text = "X"
            Else
                lblPrefix4.Text = "X"
                lblPrefix5.Text = qryCust(0).PREFIXTH
            End If

            lblENName.Text = (qryCust(0).cust.ENFIRSTNAME + "&nbsp;&nbsp;&nbsp;" + qryCust(0).cust.ENMIDNAME + "&nbsp;&nbsp;&nbsp;" + qryCust(0).cust.ENLASTNAME)
            lblENName.Text.ToUpper()
            lblFormalAddr.Text = qryCust(0).cust.FORMALADDR
            lblWorkAddr1.Text = qryCust(0).cust.WORKADDR
            lblContactAddr1.Text = qryCust(0).cust.CONTACTADDR

            lblFormalPhone.Text = qryCust(0).cust.FORMALPHONE1
            lblWorkPhone.Text = qryCust(0).cust.WORKPHONE1
            lblContactPhone.Text = qryCust(0).cust.CONTACTPHONE1

            If Not qryCust(0).cust.MARITALSTATUS Is Nothing Then

                If qryCust(0).cust.MARITALSTATUS = 1 Then
                    lblMarit1.Text = "X"
                ElseIf qryCust(0).cust.MARITALSTATUS = 2 Or qryCust(0).cust.MARITALSTATUS = 3 Or qryCust(0).cust.MARITALSTATUS = 7 Or qryCust(0).cust.MARITALSTATUS = 8 Then
                    lblMarit2.Text = "X"
                ElseIf qryCust(0).cust.MARITALSTATUS = 4 Or qryCust(0).cust.MARITALSTATUS = 10 Then
                    lblMarit3.Text = "X"
                ElseIf qryCust(0).cust.MARITALSTATUS = 6 Or qryCust(0).cust.MARITALSTATUS = 9 Then
                    lblMarit4.Text = "X"
                Else
                    lblMarit5.Text = "X"

                End If
            End If


            If Not qryCust(0).cust.CHECKNAME Is Nothing Then

                If qryCust(0).cust.CHECKNAME = 1 Then
                    lblEv1.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 2 Or qryCust(0).cust.CHECKNAME = 3 Then
                    lblEv2.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 26 Then
                    lblEv3.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 7 Or qryCust(0).cust.CHECKNAME = 8 Then
                    lblEv4.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 6 Then
                    lblEv5.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 4 Then
                    lblEv6.Text = "X"
                ElseIf qryCust(0).cust.CHECKNAME = 5 Then
                    lblEv7.Text = "X"
                Else
                    lblEv8.Text = "X"
                End If
            End If

            Dim convertDate As clsDateFormat = New clsDateFormat
            If Not qryCust(0).cust.EVEXPIRE Is Nothing Then
                lblEvExpire.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryCust(0).cust.EVEXPIRE)

                If lblEvExpire.Text = "31/12/9999" Then
                    lblEvExpire.Text = "ไม่มีวันหมดอายุ"
                End If
            Else
                lblEvExpire.Text = ""
            End If

            If Not qryCust(0).cust.BIRTHDATE Is Nothing Then
                lblBirthDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, qryCust(0).cust.BIRTHDATE)
            Else
                lblBirthDate.Text = ""
            End If


            convertDate = Nothing

            If Not qryCust(0).cust.CUSTIDTYPE Is Nothing Then
                If qryCust(0).cust.CUSTIDTYPE = 1 Then
                    lblCustIDtype1.Text = "X"
                Else
                    lblCustIDtype2.Text = "X"

                End If
            End If
            lblUniqueID.Text = qryCust(0).cust.UNIQUEID

            lblNational.Text = convertThai(qryCust(0).NATIONALITYNAME)
            If lblNational.Text = "ไทย" Then
                lblChkAddr1.Text = "X"
                lblChkNation1.Text = "X"
                lblNational.Text = ""
            Else
                lblChkAddr2.Text = "X"
                lblChkNation2.Text = "X"

            End If

            lblIncome.Text = convertThai(qryCust(0).incomes1)
            If lblIncome.Text = "ไทย" Then
                lblChkIncome1.Text = "X"
                lblIncome.Text = ""
            Else
                lblChkIncome2.Text = "X"
            End If


            If Not qryCust(0).cust.INCOMESOURCE2 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes2)
            End If
            If Not qryCust(0).cust.INCOMESOURCE3 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes3)
            End If

            If Not qryCust(0).cust.OCCUPATIONTYPE1 Is Nothing Then
                If qryCust(0).cust.OCCUPATIONTYPE1 = 1 Then
                    lblOcc1.Text = "X"
                ElseIf qryCust(0).cust.OCCUPATIONTYPE1 = 2 Then
                    lblOcc2.Text = "X"
                ElseIf qryCust(0).cust.OCCUPATIONTYPE1 = 3 Then
                    lblOcc3.Text = "X"
                ElseIf qryCust(0).cust.OCCUPATIONTYPE1 = 4 Then
                    lblOcc4.Text = "X"
                ElseIf qryCust(0).cust.OCCUPATIONTYPE1 = 98 Then
                    lblOcc5.Text = "X"
                    If qryCust(0).cust.BIZTYPE1 = 99 Then
                        lblBiz.Text = qryCust(0).cust.BIZTYPEOTHER1
                    Else
                        lblBiz.Text = qryCust(0).BIZNAME
                    End If
                ElseIf qryCust(0).cust.OCCUPATIONTYPE1 = 99 Then
                    lblOcc6.Text = "X" 'ยังไม่ครบ
                    lblOccOther.Text = qryCust(0).cust.OCCUPATIONTYPEOTHER1
                Else
                    lblOcc6.Text = "X" 'ยังไม่ครบ
                    lblOccOther.Text = qryCust(0).OCCNAME
                End If
            End If
            'If qryCust(0).cust.ISANSWERSARALY = 1 Then
            '    Dim tempSalary As Double
            '    tempSalary = qryCust(0).cust.SALARYPERMONTH()
            '    lblSalary.Text = String.Format("{0:n}", tempSalary)

            'Else
            '    lblSalary.Text = "-"
            'End If 
            Dim tempSalary As Double
            tempSalary = qryCust(0).cust.SALARYPERMONTH()
            lblSalary.Text = String.Format("{0:n}", tempSalary)

            lblCustCode.Text = qryCust(0).cust.CUSTCODE
        End If

        qryCust = Nothing

    End Sub

    Private Sub userPrint()

        Dim convertDate As clsDateFormat = New clsDateFormat
        Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
        clsSessionMenuRight = Session("clsMenuRight")

        '  lblPrint.Text = "วันที่พิมพ์ : " + convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date) + "&nbsp;&nbsp;" + Now.ToShortTimeString + "&nbsp;&nbsp;" + " /ผู้พิมพ์ : " + clsSessionMenuRight.getEmpFirstName + "&nbsp;&nbsp;" + clsSessionMenuRight.getEmpLastName
        lblUserName.Text = clsSessionMenuRight.getEmpFirstName + "&nbsp;&nbsp;" + clsSessionMenuRight.getEmpLastName
        lblPrintDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
        lblUserID.Text = clsSessionMenuRight.getUserName
        lblBranch.Text = clsSessionMenuRight.getBranchName

        convertDate = Nothing
        clsSessionMenuRight = Nothing

    End Sub

    Private Function convertThai(ByVal country As String) As String
        Dim str As String = ""
        If country = "THAI" Or country = "THAILAND" Then
            str = "ไทย"
        Else
            str = country
        End If

        Return str
    End Function


End Class
